﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface; 

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTOpeningAppraisalService : ServiceHandle, IRPTOpeningAppraisal
    {
        #region IRPTOpeningAppraisal Members

        public OperationResult<List<tb_RPT_OpeningAppraisal>> GetAllOpeningAppraisal()
        {
            OperationResult<List<tb_RPT_OpeningAppraisal>> result = new OperationResult<List<tb_RPT_OpeningAppraisal>>();
            List<tb_RPT_OpeningAppraisal> list = new List<tb_RPT_OpeningAppraisal>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllOpeningAppraisal();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_OpeningAppraisal>> GetOpeningAppraisalBySequence(string strSequence)
        {
            OperationResult<List<tb_RPT_OpeningAppraisal>> result = new OperationResult<List<tb_RPT_OpeningAppraisal>>();
            List<tb_RPT_OpeningAppraisal> list = new List<tb_RPT_OpeningAppraisal>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetOpeningAppraisalBySequence(strSequence);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_OpeningAppraisal>> GetOpeningAppraisalByProjectName(string strProjectName)
        {
            OperationResult<List<tb_RPT_OpeningAppraisal>> result = new OperationResult<List<tb_RPT_OpeningAppraisal>>();
            List<tb_RPT_OpeningAppraisal> list = new List<tb_RPT_OpeningAppraisal>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetOpeningAppraisalByProjectName(strProjectName);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_OpeningAppraisal>> GetOpeningAppraisalByContition(string strReportSequence, string strSequence, string strIDSequence, string strMixingEquipment, string strProjectName, string strConstructionUnit)
        {
            OperationResult<List<tb_RPT_OpeningAppraisal>> result = new OperationResult<List<tb_RPT_OpeningAppraisal>>();
            List<tb_RPT_OpeningAppraisal> list = new List<tb_RPT_OpeningAppraisal>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetOpeningAppraisalByContition(strReportSequence, strSequence, strIDSequence, strMixingEquipment, strProjectName, strConstructionUnit);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_OpeningAppraisal> GetOpeningAppraisalById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_OpeningAppraisal> result = new OperationResult<tb_RPT_OpeningAppraisal>();
            tb_RPT_OpeningAppraisal openingAppraisal;
            try
            {
                openingAppraisal = dataContext.GetOpeningAppraisalById(id);
                if (openingAppraisal == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = openingAppraisal;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_OpeningAppraisal> CreateOpeningAppraisal(tb_RPT_OpeningAppraisal entity)
        {
            OperationResult<tb_RPT_OpeningAppraisal> result = new OperationResult<tb_RPT_OpeningAppraisal>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateOpeningAppraisal(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_OpeningAppraisal> ModifyOpeningAppraisal(tb_RPT_OpeningAppraisal entity)
        {
            OperationResult<tb_RPT_OpeningAppraisal> result = new OperationResult<tb_RPT_OpeningAppraisal>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyOpeningAppraisal(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_OpeningAppraisal> DeleteOpeningAppraisal(tb_RPT_OpeningAppraisal entity)
        {
            OperationResult<tb_RPT_OpeningAppraisal> result = new OperationResult<tb_RPT_OpeningAppraisal>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteOpeningAppraisal(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
